package com.ys.service.overseas.impl;

import com.alibaba.fastjson.JSON;
import com.ys.dto.AddDto;
import com.ys.dto.EditDto;
import com.ys.entity.base.TbPlatform;
import com.ys.entity.overseas.TosPlatformInformation;
import com.ys.entity.sys.TsUserChange;
import com.ys.mapper.overseas.TosPlatformInformationMapper;
import com.ys.service.overseas.TosPlatformInformationService;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author: fxz
 * @CreateTime: 2024-12-17
 * @Description: HW平台信息维护
 * @Version: 1.5
 */
@Service("tosPlatformInformationService")
public class TosPlatformInformationServiceImpl implements TosPlatformInformationService {

    @Autowired
    private TosPlatformInformationMapper tosPlatformInformationMapper;

    /**
     * 新增
     * @param params
     * @return
     * @throws Exception
     */
    @Override
    public R add(Map<String, Object> params) throws Exception {
        TosPlatformInformation entity = JSON.parseObject(JSON.toJSONString(params), TosPlatformInformation.class);
        TsUserChange tsUserChange = new TsUserChange().setUserId(ShiroUtils.getUserId()).setOrderby("A.CreateTime DESC").queryFirst();
        entity.setCreateChangeId(tsUserChange.getId());
        tosPlatformInformationMapper.insert(entity);
        return R.ok(AddDto.closeAndReload());
    }

    @Override
    public R edit(Map<String, Object> params) throws Exception {
        TosPlatformInformation entity = JSON.parseObject(JSON.toJSONString(params), TosPlatformInformation.class);
        tosPlatformInformationMapper.update(entity);
        return R.ok(EditDto.closeAndReload());
    }
}
